using System.Linq;
using Core.Contracts.Interfaces;

namespace Core.Features
{
    using System;
    using Base;
    using Contracts.Enums;
    using Resources;

    
    public sealed class MinedAmount<T> : FeatureBase<object>
    {
        public MinedAmount(){}

        public MinedAmount(T value) 
            : base(value){ }
        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Mined amount"; }
        }
        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup{ get { return FeatureGroupsEnum.Specific; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.MinedAmount; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_points; } }

        public override void SetModifiedValue(IAgent agent, IRobot robot)
        {
            if (robot == null || agent == null) return;

            // Bonus from bots
            double robotBonus = robot.Modifiers.SumModifiersValues(agent.Extensions, FeatureTypesEnum.Module, this.FeatureType);

            double temp = (double)Value * (1 + robotBonus);

            // Bonus from Industrial tunnings
            temp = robot.Modules.Aggregate(
                temp,
                (current, modifier) => current*(1 + Math.Abs(modifier.Value)),
                FeatureTypesEnum.Module, this.FeatureType, ModuleGroupsEnum.IndustrialTunings);

            ModifiedValue = IsRounded
                                ? Math.Round(temp, 0, MidpointRounding.AwayFromZero)
                                : Math.Round(temp, 2);
        }
    }
}